﻿
//案由一级下拉框切换
function onFirstSltChange(el) {

    var ID = getselectValue(el);
    document.getElementById("hdnID").value = ID;
    var entity = {}
    entity.pId = "";
    entity.isId = false;

    var sltSecond = document.getElementById("sltSecondList");
    var sltThird = document.getElementById("sltThirdList");
    var sltFourth = document.getElementById("sltFourthList");

    DelSltOption(sltSecond);
    DelSltOption(sltThird);
    DelSltOption(sltFourth);

    //填充二级下拉框
    entity = AddSelectOption(sltSecond, aSecondList, ID);
    if (!entity.isId) {
        return;
    }

    //填充三级下拉框
    entity = AddSelectOption(sltThird, aThirdList, entity.pId);

    if (!entity.isId) {
        return;
    }
    //填充四级下拉框
    entity = AddSelectOption(sltFourth, aFourthList, entity.pId);
}
//案由二级下拉框切换
function onSecondSltChange(el) {
    var ID = getselectValue(el);
    document.getElementById("hdnID").value = ID;

    var entity = {}
    entity.pId = "";
    entity.isId = false;

    var sltThird = document.getElementById("sltThirdList");
    var sltFourth = document.getElementById("sltFourthList");

    DelSltOption(sltThird);
    DelSltOption(sltFourth);


    //填充三级下拉框
    entity = AddSelectOption(sltThird, aThirdList, ID);

    if (!entity.isId) {
        return;
    }

    //填充四级下拉框
    entity = AddSelectOption(sltFourth, aFourthList, entity.pId);
}

//案由三级下拉框切换
function onThirdSltChange(el) {
    var ID = getselectValue(el);
    document.getElementById("hdnID").value = ID;

    var entity = {}
    entity.pId = "";
    entity.isId = false;

    var sltFourth = document.getElementById("sltFourthList");

    DelSltOption(sltFourth);

    //填充四级下拉框
    entity = AddSelectOption(sltFourth, aFourthList, ID);
}

//案由四级下拉框切换
function onFourthSltChange(el) {
    var ID = getselectValue(el);
    document.getElementById("hdnID").value = ID;
}

//下拉框新增类
function AddSelectOption(slt, alist, parentId) {
    var entity = {}
    entity.pId = "";
    entity.isId = false;
    //填充四级下拉框
    for (var s = 0; s < alist.length; s++) {
        if (alist[s].ParentID == parentId) {
            if (!entity.isId) {
                entity.pId = alist[s].CauseOfActionID
                entity.isId = true;
            }

            var eItem = new Option(alist[s].CauseOfAction, alist[s].CauseOfActionID);
            slt.options.add(eItem);
        }
    }

    if (!entity.isId) {
        slt.parentNode.className = "g_dn";
    } else {
        slt.parentNode.className = "";
    }

    return entity;
}

//删除下拉框的元素
function DelSltOption(el) {
    for (var i = 0; i < el.options.length; ) {
        el.removeChild(el.options[i]);
    }

    el.options.add(new Option("", ""));
}

